import { _decorator, Component, Node, UI, Label, Game, clamp01, Sprite, clamp } from 'cc';
import { BasicUI } from '../../Init/Basic/BasicUI';
import { GlobalConfig } from '../../Init/Config/GlobalConfig';
import { GlobalTmpData } from '../../Init/Config/GlobalTmpData';
import EventManager from '../../Init/Managers/EventManager';
import { EventTypes } from '../../Init/Managers/EventTypes';
import { AudioEnum } from '../../Init/SystemAudio/AudioEnum';
import { AudioSystem } from '../../Init/SystemAudio/AudioSystem';
import { StorageSystem } from '../../Init/SystemStorage/StorageSystem';
import { UIEnum } from '../../Init/SystemUI/UIEnum';
import { UISystem } from '../../Init/SystemUI/UISystem';
const { ccclass, property } = _decorator;

@ccclass('WinUI')
export class WinUI extends BasicUI {

    public show() {
        super.show();
        UISystem.hideUI(UIEnum.LevelInfoUI);
        // UISystem.showUI(UIEnum.PlayerAssetsUI);
        AudioSystem.playEffect(AudioEnum.Win);

        //
        this.showAwards();
        this.showAd();

    }
    // #region --------奖励--------- 
    private _awardNum = 0;
    private showAwards() {

    }

    private saveAwards() {
        if (this._awardNum > 0) {
            StorageSystem.setData((d) => {
                d.userAssets.asset += this._awardNum;
            }, true);
            StorageSystem.updateToAssets(true, true);
        }

        UISystem.hideUI(UIEnum.WinUI);
        this.emit(EventTypes.GameEvents.SetLevelManagerEnable, false); //清除关卡场景
        UISystem.showUI(UIEnum.HomeUI);
        UISystem.hideUI(UIEnum.LevelPanelUI);
    }
    //  #endregion

    // #region --------按钮--------- 

    //多倍领取
    protected onVideoClick() {
        this.emit(EventTypes.SDKEvents.ShowVideo, {
            success: () => {
                //观看视频成功
                this._awardNum *= GlobalConfig.Award.WinVideoRate;
                this.onCloseClick();
            },
            fail: () => {

            },
            cancel: () => {

            },
        })
    }
    //直接关闭-普通领取
    protected onCloseClick() {
        this.saveAwards();
    }


    @property(Node)
    shareBtn: Node = null;
    //分享按钮
    protected onShareClick() {
        if (!this.shareBtn) return;
        EventManager.emit(EventTypes.SDKEvents.ShareRecord, () => {
            this.shareBtn.active = false;
        });
    }

    // #endregion

    // #region --------广告----------
    private showAd() {

    }

    //#endregion
}


